package com.awspaas.user.apps.processforsap.web;

import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile;
import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.formfile.model.delegate.FormFile;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.RequestParams;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.server.bind.annotation.Controller;
import com.actionsoft.bpms.server.bind.annotation.Mapping;
import com.actionsoft.bpms.server.fs.DCContext;
import com.actionsoft.bpms.server.fs.dc.DCProfileManager;
import com.actionsoft.sdk.local.SDK;
import com.alipay.sofa.common.profile.StringUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Controller
public class SapImportController {
    private static final String EXTENSION_XLS = ".xls";
    private static final String EXTENSION_XLSX = ".xlsx";

    @Mapping(value = "sap.download")
    public static String upFile(UserContext uc, String bindId) {
        ResponseObject responseObject = ResponseObject.newOkResponse("下载成功");
        String sessionId = uc.getSessionId();
        InputStream file = null;
        FileOutputStream excelFile = null;
        //日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
//        String[] fileNames = {"PROJECT_NAME", "PROJECT_NO", "PROJECT_DEPARTMENT", "XMJL", "SGJL", "FY_DATE", "FY_SCORE", "GQ_DATE", "GQ_SCORE", "TH_DATE", "TH_SCORE", "GS_DATE", "GS_SCORE", "IS_OK", "QUALITY_SCORE", "QUALITY_END", "SAFE_CHECK", "SAFE_SCORE", "SAFE_CHECK1", "SAFE_SCORE1", "SECURE_SCORE", "SCORE", "SECURE"};
//        String[] numFileNames = {"FY_SCORE", "GQ_SCORE", "TH_SCORE", "GS_SCORE", "QUALITY_SCORE", "QUALITY_END", "SAFE_SCORE", "SAFE_SCORE1", "SECURE_SCORE", "SCORE"};
        try {
            BO importModel = SDK.getBOAPI().query("BO_EU_MM_DCMB").addQuery("MODEL_ID = 'SAPFROWL'", null).detail();//导入模板表
            if (importModel != null) {
                String name="";
                String fileModel = importModel.getString("MODEL_FILE");
                if (fileModel != null && !"".equals(fileModel)) { //如果文件不为空
                    /** 获取对应附件 */
                    List<FormFile> file_model = SDK.getBOAPI().getFiles(importModel.getId(), "MODEL_FILE");
                    file = SDK.getBOAPI().getFile(file_model.get(0).getId());
                    /** 将对应附件解析 */
                    Workbook wb = null;
                    if (fileModel.endsWith(EXTENSION_XLS)) {
                        wb = new HSSFWorkbook(file);
                    } else if (fileModel.endsWith(EXTENSION_XLSX)) {
                        wb = new XSSFWorkbook(file);
                    }
                    int costIndex = 6;//项目费用清单行坐标
                    /** 找到对应行数据,并且将数据赋值进表格中 */
                    DecimalFormat df = new DecimalFormat("#.00");
                    if (wb != null) {
                        Sheet sheet = wb.getSheetAt(0);
                        if (costIndex > 0) {
                            //获取基础视图
                            List<BO> projectList = SDK.getBOAPI().query("BO_EU_SAP_JBST").bindId(bindId).list();
                            List<BO> flList = SDK.getBOAPI().query("BO_EU_SAP_FLST").bindId(bindId).list();
                            List<BO> xsList = SDK.getBOAPI().query("BO_EU_SAP_XSST").bindId(bindId).list();
                            List<BO> cgList = SDK.getBOAPI().query("BO_EU_SAP_CGST").bindId(bindId).list();
                            List<BO> ccList = SDK.getBOAPI().query("BO_EU_SAP_CCST").bindId(bindId).list();
                            List<BO> cwList = SDK.getBOAPI().query("BO_EU_SAP_CWST").bindId(bindId).list();
                            List<BO> mrpList = SDK.getBOAPI().query("BO_EU_SAP_MRP").bindId(bindId).list();
                            List<BO> gzList = SDK.getBOAPI().query("BO_EU_SAP_GZJH").bindId(bindId).list();
                            for (int i = 0; i < projectList.size(); i++) {
                                //获取行数据
                                BO bo = projectList.get(i);
                                String material = bo.getString("MATERIAL");
                                name = material;

                                String id = bo.getId();
                                if (i == 0) {
                                    Row row = sheet.getRow(costIndex);//创建对应行数据
                                    Cell cellType0 = row.getCell(0);
                                    Cell cellType1 = row.getCell(1);
                                    Cell cellType2 = row.getCell(2);
                                    Cell cellType3 = row.getCell(3);
                                    Cell cellType4 = row.getCell(4);
                                    Cell cellType5 = row.getCell(5);
                                    Cell cellType6 = row.getCell(6);
                                    Cell cellType7 = row.getCell(7);
                                    Cell cellType8 = row.getCell(8);
                                    Cell cellType9 = row.getCell(9);
                                    Cell cellType10 = row.getCell(10);
                                    Cell cellType11 = row.getCell(11);
                                    Cell cellType12 = row.getCell(12);
                                    Cell cellType13 = row.getCell(13);
                                    Cell cellType14 = row.getCell(14);
                                    Cell cellType15 = row.getCell(15);
                                    Cell cellType16 = row.getCell(16);
                                    Cell cellType17 = row.getCell(17);
                                    Cell cellType18 = row.getCell(18);
                                    Cell cellType19 = row.getCell(19);
                                    Cell cellType20 = row.getCell(20);
                                    Cell cellType21 = row.getCell(21);
                                    Cell cellType22 = row.getCell(22);
                                    Cell cellType23 = row.getCell(23);
                                    Cell cellType24 = row.getCell(24);
                                    Cell cellType25 = row.getCell(25);
                                    Cell cellType26 = row.getCell(26);
                                    Cell cellType27 = row.getCell(27);
                                    Cell cellType28 = row.getCell(28);
                                    Cell cellType29 = row.getCell(29);
                                    Cell cellType30 = row.getCell(30);
                                    Cell cellType31 = row.getCell(31);
                                    Cell cellType32 = row.getCell(32);
                                    Cell cellType33 = row.getCell(33);
                                    Cell cellType34 = row.getCell(34);
                                    Cell cellType35 = row.getCell(35);
                                    Cell cellType36 = row.getCell(36);
                                    Cell cellType37 = row.getCell(37);
                                    Cell cellType38 = row.getCell(38);
                                    Cell cellType39 = row.getCell(39);
                                    Cell cellType40 = row.getCell(40);
                                    Cell cellType41 = row.getCell(41);
                                    Cell cellType42 = row.getCell(42);
                                    Cell cellType43 = row.getCell(43);
                                    Cell cellType44 = row.getCell(44);
                                    Cell cellType45 = row.getCell(45);
                                    Cell cellType46 = row.getCell(46);
                                    Cell cellType47 = row.getCell(47);
                                    Cell cellType48 = row.getCell(48);
                                    Cell cellType49 = row.getCell(49);
                                    Cell cellType50 = row.getCell(50);
                                    Cell cellType51 = row.getCell(51);
                                    Cell cellType52 = row.getCell(52);
                                    Cell cellType53 = row.getCell(53);
                                    Cell cellType54 = row.getCell(54);
                                    Cell cellType55 = row.getCell(55);
                                    Cell cellType56 = row.getCell(56);
                                    Cell cellType57 = row.getCell(57);
                                    Cell cellType58 = row.getCell(58);
                                    Cell cellType59 = row.getCell(59);
                                    Cell cellType60 = row.getCell(60);
                                    Cell cellType61 = row.getCell(61);
                                    Cell cellType62 = row.getCell(62);
                                    Cell cellType63 = row.getCell(63);
                                    Cell cellType64 = row.getCell(64);
                                    Cell cellType65 = row.getCell(65);
                                    Cell cellType66 = row.getCell(66);
                                    Cell cellType67 = row.getCell(67);
                                    Cell cellType68 = row.getCell(68);
                                    Cell cellType69 = row.getCell(69);
                                    Cell cellType70 = row.getCell(70);
                                    Cell cellType71 = row.getCell(71);
                                    Cell cellType72 = row.getCell(72);
                                    Cell cellType73 = row.getCell(73);
                                    Cell cellType74 = row.getCell(74);
                                    Cell cellType75 = row.getCell(75);
                                    Cell cellType76 = row.getCell(76);
                                    Cell cellType77 = row.getCell(77);
                                    Cell cellType78 = row.getCell(78);
                                    Cell cellType79 = row.getCell(79);
                                    Cell cellType80 = row.getCell(80);
                                    Cell cellType81 = row.getCell(81);
                                    Cell cellType82 = row.getCell(82);
                                    Cell cellType83 = row.getCell(83);
                                    Cell cellType84 = row.getCell(84);
                                    Cell cellType85 = row.getCell(85);
                                    Cell cellType86 = row.getCell(86);
                                    Cell cellType87 = row.getCell(87);
                                    Cell cellType88 = row.getCell(88);
                                    Cell cellType89 = row.getCell(89);
                                    Cell cellType90 = row.getCell(90);
                                    Cell cellType91 = row.getCell(91);
                                    Cell cellType92 = row.getCell(92);
                                    Cell cellType93 = row.getCell(93);
                                    Cell cellType94 = row.getCell(94);
                                    Cell cellType95 = row.getCell(95);
                                    Cell cellType96 = row.getCell(96);
                                    Cell cellType97 = row.getCell(97);
                                    Cell cellType98 = row.getCell(98);
                                    Cell cellType99 = row.getCell(99);
                                    Cell cellType100 = row.getCell(100);
                                    Cell cellType101 = row.getCell(101);
                                    Cell cellType102 = row.getCell(102);
                                    Cell cellType103 = row.getCell(103);
                                    Cell cellType104 = row.getCell(104);
                                    Cell cellType105 = row.getCell(105);
                                    Cell cellType106 = row.getCell(106);
                                    Cell cellType107 = row.getCell(107);
                                    Cell cellType108 = row.getCell(108);
                                    //赋值
                                    cellType0.setCellValue(i + 1);
                                    //基础视图
                                    cellType1.setCellValue(bo.getString("IND_SECTOR"));
                                    cellType2.setCellValue(bo.getString("BASIC_VIEW"));
                                    cellType3.setCellValue(bo.getString("LANGU"));
                                    cellType4.setCellValue(bo.getString("PLANT"));
                                    cellType5.setCellValue(bo.getString("AVAILCHECK"));
                                    cellType6.setCellValue(bo.getString("MATL_TYPE"));
                                    cellType7.setCellValue(bo.getString("OLD_MAT_NO"));
                                    cellType8.setCellValue(bo.getString("MATERIAL"));
                                    cellType9.setCellValue(bo.getString("MATL_DESC"));
                                    cellType10.setCellValue(bo.getString("TEXT_LINE"));
                                    cellType11.setCellValue(bo.getString("BASE_UOM"));
                                    cellType12.setCellValue(bo.getString("MATL_GROUP"));
                                    cellType13.setCellValue(bo.getString("PROD_HIER"));
                                    cellType14.setCellValue(bo.getString("SIZE_DIM"));
                                    cellType15.setCellValue(bo.getString("BASIC_MATL"));
                                    cellType16.setCellValue(bo.getString("PAGEFORMAT"));
                                    cellType17.setCellValue(bo.getString("PROD_MEMO"));
                                    cellType18.setCellValue(bo.getString(""));
                                    //分类视图
                                    List<BO> fl = flList.stream().filter(bo1 -> bo1.getString("MAINID").equals(id)).collect(Collectors.toList());
                                    if (fl != null && fl.size() > 0) {
                                        bo = fl.get(0);
                                        cellType19.setCellValue(bo.getString("CLASS_VIEW"));
                                        cellType20.setCellValue(bo.getString("CLASSTYPE"));
                                        cellType21.setCellValue(bo.getString("CLASSNUM"));
                                    }
                                    //销售视图
                                    List<BO> xs = xsList.stream().filter(bo1 -> bo1.getString("MAINID").equals(id)).collect(Collectors.toList());
                                    if (xs != null && xs.size() > 0) {
                                        bo = xs.get(0);
                                        cellType22.setCellValue(bo.getString("SALES_VIEW"));
                                        cellType23.setCellValue(bo.getString("SALES_ORG"));
                                        cellType24.setCellValue(bo.getString("DISTR_CHAN"));
                                        cellType25.setCellValue(bo.getString("DIVISION"));
                                        cellType26.setCellValue(bo.getString("DEPCOUNTRY"));
                                        cellType27.setCellValue(bo.getString("TAXCLASS_4"));
                                        cellType28.setCellValue(bo.getString("TAX_TYPE_4"));
                                        cellType29.setCellValue(bo.getString("ITEM_CAT"));
                                        cellType30.setCellValue(bo.getString("ACCT_ASSGT"));
                                        cellType31.setCellValue(bo.getString("TRANS_GRP"));
                                        cellType32.setCellValue(bo.getString("LOADINGGRP"));
                                    }
                                    //采购视图
                                    List<BO> cg = cgList.stream().filter(bo1 -> bo1.getString("MAINID").equals(id)).collect(Collectors.toList());
                                    if (cg != null && cg.size() > 0) {
                                        bo = cg.get(0);
                                        cellType33.setCellValue(bo.getString("PURCHASE_VIEW"));
                                        cellType34.setCellValue(bo.getString("PUR_GROUP"));
                                        cellType35.setCellValue(bo.getString("AUTO_P_ORD"));
                                        cellType36.setCellValue(bo.getString("SOURCELIST"));
                                    }

                                    //存储视图
                                    List<BO> cc = ccList.stream().filter(bo1 -> bo1.getString("MAINID").equals(id)).collect(Collectors.toList());
                                    if (cc != null && cc.size() > 0) {
                                        bo = cc.get(0);
                                        cellType37.setCellValue(bo.getString("STORAGE_VIEW"));
                                        cellType38.setCellValue(bo.getString("STGE_LOC"));
                                        cellType39.setCellValue(bo.getString("BATCH_MGMT_GL"));
                                        cellType40.setCellValue(bo.getString("BATCH_MGMT_BS"));
                                        cellType41.setCellValue(bo.getString("MINREMLIFE"));
                                        cellType42.setCellValue(bo.getString("SHELF_LIFE"));
                                        cellType43.setCellValue(bo.getString("PERIOD_IND_EXPIRATION_DATE"));
                                        cellType44.setCellValue(bo.getString("ISSUE_UNIT"));
                                    }
                                    //会计视图
                                    List<BO> kj = cwList.stream().filter(bo1 -> bo1.getString("MAINID").equals(id)).collect(Collectors.toList());
                                    if (kj != null && kj.size() > 0) {
                                        bo = kj.get(0);
                                        cellType45.setCellValue(bo.getString("ACCOUNT_VIEW"));
                                        cellType46.setCellValue(bo.getString("COST_VIEW"));
                                        cellType47.setCellValue(bo.getString("VAL_AREA"));
                                        cellType48.setCellValue(bo.getString("VAL_CLASS"));
                                        cellType49.setCellValue(bo.getString("PRICE_CTRL"));
                                        cellType50.setCellValue(bo.getString("ML_SETTLE"));
                                        cellType51.setCellValue(bo.getString("MOVING_PR"));
                                        cellType52.setCellValue(bo.getString("STD_PRICE"));
                                        cellType53.setCellValue(bo.getString("PRICE_UNIT"));
                                        cellType54.setCellValue(bo.getString("NCOST"));
                                        cellType55.setCellValue(bo.getString("QTY_STRUCT"));
                                        cellType56.setCellValue(bo.getString("ORIG_MAT"));
                                        cellType57.setCellValue(bo.getString("ORIG_GROUP"));
                                        cellType58.setCellValue(bo.getString("VARIANCE_KEY"));
                                        cellType59.setCellValue(bo.getString("PROFIT_CTR"));
                                        cellType60.setCellValue(bo.getString("LOT_SIZE"));
                                    }
                                    //MRP视图
                                    List<BO> mrp = mrpList.stream().filter(bo1 -> bo1.getString("MAINID").equals(id)).collect(Collectors.toList());
                                    if (mrp != null && mrp.size() > 0) {
                                        bo = mrp.get(0);
                                        cellType61.setCellValue(bo.getString("MRP_VIEW"));
                                        cellType62.setCellValue(bo.getString("MRP_GROUP"));
                                        cellType63.setCellValue(bo.getString("PL_TI_FNCE"));
                                        cellType64.setCellValue(bo.getString("MRP_TYPE"));
                                        cellType65.setCellValue(bo.getString("MRP_CTRLER"));
                                        cellType66.setCellValue(bo.getString("LOTSIZEKEY"));
                                        cellType67.setCellValue(bo.getString("MINLOTSIZE"));
                                        cellType68.setCellValue(bo.getString("MAXLOTSIZE"));
                                        cellType69.setCellValue(bo.getString("FIXED_LOT"));
                                        cellType70.setCellValue(bo.getString("ROUND_VAL"));
                                        cellType71.setCellValue(bo.getString("REORDER_PT"));
                                        cellType72.setCellValue(bo.getString("MAX_STOCK"));
                                        cellType73.setCellValue(bo.getString("ASSY_SCRAP"));
                                        cellType74.setCellValue(bo.getString("PUR_STATUS"));
                                        cellType75.setCellValue(bo.getString("BERID"));
                                        cellType76.setCellValue(bo.getString("DISMM"));
                                        cellType77.setCellValue(bo.getString("PROC_TYPE"));
                                        cellType78.setCellValue(bo.getString("SPPROCTYPE"));
                                        cellType79.setCellValue(bo.getString("ISS_ST_LOC"));
                                        cellType80.setCellValue(bo.getString("SLOC_EXPRC"));
                                        cellType81.setCellValue(bo.getString("BULK_MAT"));
                                        cellType82.setCellValue(bo.getString("BACKFLUSH"));
                                        cellType83.setCellValue(bo.getString("INHSEPRODT"));
                                        cellType84.setCellValue(bo.getString("GR_PR_TIME"));
                                        cellType85.setCellValue(bo.getString("PLND_DELRY"));
                                        cellType86.setCellValue(bo.getString("SAFETY_STK"));
                                        cellType87.setCellValue(bo.getString("SM_KEY"));
                                        cellType88.setCellValue(bo.getString("PLAN_STRGP"));
                                        cellType89.setCellValue(bo.getString("CONSUMMODE"));
                                        cellType90.setCellValue(bo.getString("BWD_CONS"));
                                        cellType91.setCellValue(bo.getString("FWD_CONS"));
                                        cellType92.setCellValue(bo.getString("MISKZ"));
                                        cellType93.setCellValue(bo.getString("VPMAT"));
                                        cellType94.setCellValue(bo.getString("VPWRK"));
                                        cellType95.setCellValue(bo.getString("VPREF"));
                                        cellType96.setCellValue(bo.getString("DEP_REQ_ID"));
                                        cellType97.setCellValue(bo.getString("COMP_SCRAP"));
                                        cellType98.setCellValue(bo.getString("MRP_RELEVANCY_DEP_REQUIREMENTS"));
                                        cellType99.setCellValue(bo.getString("DISCONTINU"));
                                        cellType100.setCellValue(bo.getString("EFF_O_DAY"));
                                        cellType101.setCellValue(bo.getString("FOLLOW_UP"));
                                    }
                                    //工作计划
                                    List<BO> gz = gzList.stream().filter(bo1 -> bo1.getString("MAINID").equals(id)).collect(Collectors.toList());
                                    if (gz != null && gz.size() > 0) {
                                        bo = gz.get(0);
                                        cellType102.setCellValue(bo.getString("WORK_SCHED_VIEW"));
                                        cellType103.setCellValue(bo.getString("PRODPROF"));
                                        cellType104.setCellValue(bo.getString("PRODUCTION_SCHEDULER"));
                                        cellType105.setCellValue(bo.getString("ISSUE_UNIT"));
                                        cellType106.setCellValue(bo.getString("UNDER_TOL"));
                                        cellType107.setCellValue(bo.getString("OVER_TOL"));
                                        cellType108.setCellValue(bo.getString("UNLIMITED"));
                                    }
                                } else {
                                    Row target = sheet.getRow(costIndex);//创建对应行数据
                                    Row row = sheet.createRow(i + costIndex);
                                    //序号
                                    Cell cellType0 = row.createCell(0);
                                    Cell cellType1 = row.createCell(1);
                                    Cell cellType2 = row.createCell(2);
                                    Cell cellType3 = row.createCell(3);
                                    Cell cellType4 = row.createCell(4);
                                    Cell cellType5 = row.createCell(5);
                                    Cell cellType6 = row.createCell(6);
                                    Cell cellType7 = row.createCell(7);
                                    Cell cellType8 = row.createCell(8);
                                    Cell cellType9 = row.createCell(9);
                                    Cell cellType10 = row.createCell(10);
                                    Cell cellType11 = row.createCell(11);
                                    Cell cellType12 = row.createCell(12);
                                    Cell cellType13 = row.createCell(13);
                                    Cell cellType14 = row.createCell(14);
                                    Cell cellType15 = row.createCell(15);
                                    Cell cellType16 = row.createCell(16);
                                    Cell cellType17 = row.createCell(17);
                                    Cell cellType18 = row.createCell(18);
                                    Cell cellType19 = row.createCell(19);
                                    Cell cellType20 = row.createCell(20);
                                    Cell cellType21 = row.createCell(21);
                                    Cell cellType22 = row.createCell(22);
                                    Cell cellType23 = row.createCell(23);
                                    Cell cellType24 = row.createCell(24);
                                    Cell cellType25 = row.createCell(25);
                                    Cell cellType26 = row.createCell(26);
                                    Cell cellType27 = row.createCell(27);
                                    Cell cellType28 = row.createCell(28);
                                    Cell cellType29 = row.createCell(29);
                                    Cell cellType30 = row.createCell(30);
                                    Cell cellType31 = row.createCell(31);
                                    Cell cellType32 = row.createCell(32);
                                    Cell cellType33 = row.createCell(33);
                                    Cell cellType34 = row.createCell(34);
                                    Cell cellType35 = row.createCell(35);
                                    Cell cellType36 = row.createCell(36);
                                    Cell cellType37 = row.createCell(37);
                                    Cell cellType38 = row.createCell(38);
                                    Cell cellType39 = row.createCell(39);
                                    Cell cellType40 = row.createCell(40);
                                    Cell cellType41 = row.createCell(41);
                                    Cell cellType42 = row.createCell(42);
                                    Cell cellType43 = row.createCell(43);
                                    Cell cellType44 = row.createCell(44);
                                    Cell cellType45 = row.createCell(45);
                                    Cell cellType46 = row.createCell(46);
                                    Cell cellType47 = row.createCell(47);
                                    Cell cellType48 = row.createCell(48);
                                    Cell cellType49 = row.createCell(49);
                                    Cell cellType50 = row.createCell(50);
                                    Cell cellType51 = row.createCell(51);
                                    Cell cellType52 = row.createCell(52);
                                    Cell cellType53 = row.createCell(53);
                                    Cell cellType54 = row.createCell(54);
                                    Cell cellType55 = row.createCell(55);
                                    Cell cellType56 = row.createCell(56);
                                    Cell cellType57 = row.createCell(57);
                                    Cell cellType58 = row.createCell(58);
                                    Cell cellType59 = row.createCell(59);
                                    Cell cellType60 = row.createCell(60);
                                    Cell cellType61 = row.createCell(61);
                                    Cell cellType62 = row.createCell(62);
                                    Cell cellType63 = row.createCell(63);
                                    Cell cellType64 = row.createCell(64);
                                    Cell cellType65 = row.createCell(65);
                                    Cell cellType66 = row.createCell(66);
                                    Cell cellType67 = row.createCell(67);
                                    Cell cellType68 = row.createCell(68);
                                    Cell cellType69 = row.createCell(69);
                                    Cell cellType70 = row.createCell(70);
                                    Cell cellType71 = row.createCell(71);
                                    Cell cellType72 = row.createCell(72);
                                    Cell cellType73 = row.createCell(73);
                                    Cell cellType74 = row.createCell(74);
                                    Cell cellType75 = row.createCell(75);
                                    Cell cellType76 = row.createCell(76);
                                    Cell cellType77 = row.createCell(77);
                                    Cell cellType78 = row.createCell(78);
                                    Cell cellType79 = row.createCell(79);
                                    Cell cellType80 = row.createCell(80);
                                    Cell cellType81 = row.createCell(81);
                                    Cell cellType82 = row.createCell(82);
                                    Cell cellType83 = row.createCell(83);
                                    Cell cellType84 = row.createCell(84);
                                    Cell cellType85 = row.createCell(85);
                                    Cell cellType86 = row.createCell(86);
                                    Cell cellType87 = row.createCell(87);
                                    Cell cellType88 = row.createCell(88);
                                    Cell cellType89 = row.createCell(89);
                                    Cell cellType90 = row.createCell(90);
                                    Cell cellType91 = row.createCell(91);
                                    Cell cellType92 = row.createCell(92);
                                    Cell cellType93 = row.createCell(93);
                                    Cell cellType94 = row.createCell(94);
                                    Cell cellType95 = row.createCell(95);
                                    Cell cellType96 = row.createCell(96);
                                    Cell cellType97 = row.createCell(97);
                                    Cell cellType98 = row.createCell(98);
                                    Cell cellType99 = row.createCell(99);
                                    Cell cellType100 = row.createCell(100);
                                    Cell cellType101 = row.createCell(101);
                                    Cell cellType102 = row.createCell(102);
                                    Cell cellType103 = row.createCell(103);
                                    Cell cellType104 = row.createCell(104);
                                    Cell cellType105 = row.createCell(105);
                                    Cell cellType106 = row.createCell(106);
                                    Cell cellType107 = row.createCell(107);
                                    Cell cellType108 = row.createCell(108);
                                    //赋值
                                    cellType0.setCellValue(i + 1);
                                    //基础视图
                                    cellType1.setCellValue(bo.getString("IND_SECTOR"));
                                    cellType2.setCellValue(bo.getString("BASIC_VIEW"));
                                    cellType3.setCellValue(bo.getString("LANGU"));
                                    cellType4.setCellValue(bo.getString("PLANT"));
                                    cellType5.setCellValue(bo.getString("AVAILCHECK"));
                                    cellType6.setCellValue(bo.getString("MATL_TYPE"));
                                    cellType7.setCellValue(bo.getString("OLD_MAT_NO"));
                                    cellType8.setCellValue(bo.getString("MATERIAL"));
                                    cellType9.setCellValue(bo.getString("MATL_DESC"));
                                    cellType10.setCellValue(bo.getString("TEXT_LINE"));
                                    cellType11.setCellValue(bo.getString("BASE_UOM"));
                                    cellType12.setCellValue(bo.getString("MATL_GROUP"));
                                    cellType13.setCellValue(bo.getString("PROD_HIER"));
                                    cellType14.setCellValue(bo.getString("SIZE_DIM"));
                                    cellType15.setCellValue(bo.getString("BASIC_MATL"));
                                    cellType16.setCellValue(bo.getString("PAGEFORMAT"));
                                    cellType17.setCellValue(bo.getString("PROD_MEMO"));
                                    cellType18.setCellValue(bo.getString(""));
                                    //分类视图
                                    List<BO> fl = flList.stream().filter(bo1 -> bo1.getString("MAINID").equals(id)).collect(Collectors.toList());
                                    if (fl != null && fl.size() > 0) {
                                        bo = fl.get(0);
                                        cellType19.setCellValue(bo.getString("CLASS_VIEW"));
                                        cellType20.setCellValue(bo.getString("CLASSTYPE"));
                                        cellType21.setCellValue(bo.getString("CLASSNUM"));
                                    }
                                    //销售视图
                                    List<BO> xs = xsList.stream().filter(bo1 -> bo1.getString("MAINID").equals(id)).collect(Collectors.toList());
                                    if (xs != null && xs.size() > 0) {
                                        bo = xs.get(0);
                                        cellType22.setCellValue(bo.getString("SALES_VIEW"));
                                        cellType23.setCellValue(bo.getString("SALES_ORG"));
                                        cellType24.setCellValue(bo.getString("DISTR_CHAN"));
                                        cellType25.setCellValue(bo.getString("DIVISION"));
                                        cellType26.setCellValue(bo.getString("DEPCOUNTRY"));
                                        cellType27.setCellValue(bo.getString("TAXCLASS_4"));
                                        cellType28.setCellValue(bo.getString("TAX_TYPE_4"));
                                        cellType29.setCellValue(bo.getString("ITEM_CAT"));
                                        cellType30.setCellValue(bo.getString("ACCT_ASSGT"));
                                        cellType31.setCellValue(bo.getString("TRANS_GRP"));
                                        cellType32.setCellValue(bo.getString("LOADINGGRP"));
                                    }
                                    //采购视图
                                    List<BO> cg = cgList.stream().filter(bo1 -> bo1.getString("MAINID").equals(id)).collect(Collectors.toList());
                                    if (cg != null && cg.size() > 0) {
                                        bo = cg.get(0);
                                        cellType33.setCellValue(bo.getString("PURCHASE_VIEW"));
                                        cellType34.setCellValue(bo.getString("PUR_GROUP"));
                                        cellType35.setCellValue(bo.getString("AUTO_P_ORD"));
                                        cellType36.setCellValue(bo.getString("SOURCELIST"));
                                    }

                                    //存储视图
                                    List<BO> cc = ccList.stream().filter(bo1 -> bo1.getString("MAINID").equals(id)).collect(Collectors.toList());
                                    if (cc != null && cc.size() > 0) {
                                        bo = cc.get(0);
                                        cellType37.setCellValue(bo.getString("STORAGE_VIEW"));
                                        cellType38.setCellValue(bo.getString("STGE_LOC"));
                                        cellType39.setCellValue(bo.getString("BATCH_MGMT_GL"));
                                        cellType40.setCellValue(bo.getString("BATCH_MGMT_BS"));
                                        cellType41.setCellValue(bo.getString("MINREMLIFE"));
                                        cellType42.setCellValue(bo.getString("SHELF_LIFE"));
                                        cellType43.setCellValue(bo.getString("PERIOD_IND_EXPIRATION_DATE"));
                                        cellType44.setCellValue(bo.getString("ISSUE_UNIT"));
                                    }
                                    //会计视图
                                    List<BO> kj = cwList.stream().filter(bo1 -> bo1.getString("MAINID").equals(id)).collect(Collectors.toList());
                                    if (kj != null && kj.size() > 0) {
                                        bo = kj.get(0);
                                        cellType45.setCellValue(bo.getString("ACCOUNT_VIEW"));
                                        cellType46.setCellValue(bo.getString("COST_VIEW"));
                                        cellType47.setCellValue(bo.getString("VAL_AREA"));
                                        cellType48.setCellValue(bo.getString("VAL_CLASS"));
                                        cellType49.setCellValue(bo.getString("PRICE_CTRL"));
                                        cellType50.setCellValue(bo.getString("ML_SETTLE"));
                                        cellType51.setCellValue(bo.getString("MOVING_PR"));
                                        cellType52.setCellValue(bo.getString("STD_PRICE"));
                                        cellType53.setCellValue(bo.getString("PRICE_UNIT"));
                                        cellType54.setCellValue(bo.getString("NCOST"));
                                        cellType55.setCellValue(bo.getString("QTY_STRUCT"));
                                        cellType56.setCellValue(bo.getString("ORIG_MAT"));
                                        cellType57.setCellValue(bo.getString("ORIG_GROUP"));
                                        cellType58.setCellValue(bo.getString("VARIANCE_KEY"));
                                        cellType59.setCellValue(bo.getString("PROFIT_CTR"));
                                        cellType60.setCellValue(bo.getString("LOT_SIZE"));
                                    }
                                    //MRP视图
                                    List<BO> mrp = mrpList.stream().filter(bo1 -> bo1.getString("MAINID").equals(id)).collect(Collectors.toList());
                                    if (mrp != null && mrp.size() > 0) {
                                        bo = mrp.get(0);
                                        cellType61.setCellValue(bo.getString("MRP_VIEW"));
                                        cellType62.setCellValue(bo.getString("MRP_GROUP"));
                                        cellType63.setCellValue(bo.getString("PL_TI_FNCE"));
                                        cellType64.setCellValue(bo.getString("MRP_TYPE"));
                                        cellType65.setCellValue(bo.getString("MRP_CTRLER"));
                                        cellType66.setCellValue(bo.getString("LOTSIZEKEY"));
                                        cellType67.setCellValue(bo.getString("MINLOTSIZE"));
                                        cellType68.setCellValue(bo.getString("MAXLOTSIZE"));
                                        cellType69.setCellValue(bo.getString("FIXED_LOT"));
                                        cellType70.setCellValue(bo.getString("ROUND_VAL"));
                                        cellType71.setCellValue(bo.getString("REORDER_PT"));
                                        cellType72.setCellValue(bo.getString("MAX_STOCK"));
                                        cellType73.setCellValue(bo.getString("ASSY_SCRAP"));
                                        cellType74.setCellValue(bo.getString("PUR_STATUS"));
                                        cellType75.setCellValue(bo.getString("BERID"));
                                        cellType76.setCellValue(bo.getString("DISMM"));
                                        cellType77.setCellValue(bo.getString("PROC_TYPE"));
                                        cellType78.setCellValue(bo.getString("SPPROCTYPE"));
                                        cellType79.setCellValue(bo.getString("ISS_ST_LOC"));
                                        cellType80.setCellValue(bo.getString("SLOC_EXPRC"));
                                        cellType81.setCellValue(bo.getString("BULK_MAT"));
                                        cellType82.setCellValue(bo.getString("BACKFLUSH"));
                                        cellType83.setCellValue(bo.getString("INHSEPRODT"));
                                        cellType84.setCellValue(bo.getString("GR_PR_TIME"));
                                        cellType85.setCellValue(bo.getString("PLND_DELRY"));
                                        cellType86.setCellValue(bo.getString("SAFETY_STK"));
                                        cellType87.setCellValue(bo.getString("SM_KEY"));
                                        cellType88.setCellValue(bo.getString("PLAN_STRGP"));
                                        cellType89.setCellValue(bo.getString("CONSUMMODE"));
                                        cellType90.setCellValue(bo.getString("BWD_CONS"));
                                        cellType91.setCellValue(bo.getString("FWD_CONS"));
                                        cellType92.setCellValue(bo.getString("MISKZ"));
                                        cellType93.setCellValue(bo.getString("VPMAT"));
                                        cellType94.setCellValue(bo.getString("VPWRK"));
                                        cellType95.setCellValue(bo.getString("VPREF"));
                                        cellType96.setCellValue(bo.getString("DEP_REQ_ID"));
                                        cellType97.setCellValue(bo.getString("COMP_SCRAP"));
                                        cellType98.setCellValue(bo.getString("MRP_RELEVANCY_DEP_REQUIREMENTS"));
                                        cellType99.setCellValue(bo.getString("DISCONTINU"));
                                        cellType100.setCellValue(bo.getString("EFF_O_DAY"));
                                        cellType101.setCellValue(bo.getString("FOLLOW_UP"));
                                    }
                                    //工作计划
                                    List<BO> gz = gzList.stream().filter(bo1 -> bo1.getString("MAINID").equals(id)).collect(Collectors.toList());
                                    if (gz != null && gz.size() > 0) {
                                        bo = gz.get(0);
                                        cellType102.setCellValue(bo.getString("WORK_SCHED_VIEW"));
                                        cellType103.setCellValue(bo.getString("PRODPROF"));
                                        cellType104.setCellValue(bo.getString("PRODUCTION_SCHEDULER"));
                                        cellType105.setCellValue(bo.getString("ISSUE_UNIT"));
                                        cellType106.setCellValue(bo.getString("UNDER_TOL"));
                                        cellType107.setCellValue(bo.getString("OVER_TOL"));
                                        cellType108.setCellValue(bo.getString("UNLIMITED"));
                                    }

                                    CellStyle cellStyle0 = target.getCell(0).getCellStyle();
                                    CellStyle cellStyle1 = target.getCell(1).getCellStyle();
                                    CellStyle cellStyle2 = target.getCell(2).getCellStyle();
                                    CellStyle cellStyle3 = target.getCell(3).getCellStyle();
                                    CellStyle cellStyle4 = target.getCell(4).getCellStyle();
                                    CellStyle cellStyle5 = target.getCell(5).getCellStyle();
                                    CellStyle cellStyle6 = target.getCell(6).getCellStyle();
                                    CellStyle cellStyle7 = target.getCell(7).getCellStyle();
                                    CellStyle cellStyle8 = target.getCell(8).getCellStyle();
                                    CellStyle cellStyle9 = target.getCell(9).getCellStyle();
                                    CellStyle cellStyle10 = target.getCell(10).getCellStyle();
                                    CellStyle cellStyle11 = target.getCell(11).getCellStyle();
                                    CellStyle cellStyle12 = target.getCell(12).getCellStyle();
                                    CellStyle cellStyle13 = target.getCell(13).getCellStyle();
                                    CellStyle cellStyle14 = target.getCell(14).getCellStyle();
                                    CellStyle cellStyle15 = target.getCell(15).getCellStyle();
                                    CellStyle cellStyle16 = target.getCell(16).getCellStyle();
                                    CellStyle cellStyle17 = target.getCell(17).getCellStyle();
                                    CellStyle cellStyle18 = target.getCell(18).getCellStyle();
                                    CellStyle cellStyle19 = target.getCell(19).getCellStyle();
                                    CellStyle cellStyle20 = target.getCell(20).getCellStyle();
                                    CellStyle cellStyle21 = target.getCell(21).getCellStyle();
                                    CellStyle cellStyle22 = target.getCell(22).getCellStyle();
                                    CellStyle cellStyle23 = target.getCell(23).getCellStyle();
                                    CellStyle cellStyle24 = target.getCell(24).getCellStyle();
                                    CellStyle cellStyle25 = target.getCell(25).getCellStyle();
                                    CellStyle cellStyle26 = target.getCell(26).getCellStyle();
                                    CellStyle cellStyle27 = target.getCell(27).getCellStyle();
                                    CellStyle cellStyle28 = target.getCell(28).getCellStyle();
                                    CellStyle cellStyle29 = target.getCell(29).getCellStyle();
                                    CellStyle cellStyle30 = target.getCell(30).getCellStyle();
                                    CellStyle cellStyle31 = target.getCell(31).getCellStyle();
                                    CellStyle cellStyle32 = target.getCell(32).getCellStyle();
                                    CellStyle cellStyle33 = target.getCell(33).getCellStyle();
                                    CellStyle cellStyle34 = target.getCell(34).getCellStyle();
                                    CellStyle cellStyle35 = target.getCell(35).getCellStyle();
                                    CellStyle cellStyle36 = target.getCell(36).getCellStyle();
                                    CellStyle cellStyle37 = target.getCell(37).getCellStyle();
                                    CellStyle cellStyle38 = target.getCell(38).getCellStyle();
                                    CellStyle cellStyle39 = target.getCell(39).getCellStyle();
                                    CellStyle cellStyle40 = target.getCell(40).getCellStyle();
                                    CellStyle cellStyle41 = target.getCell(41).getCellStyle();
                                    CellStyle cellStyle42 = target.getCell(42).getCellStyle();
                                    CellStyle cellStyle43 = target.getCell(43).getCellStyle();
                                    CellStyle cellStyle44 = target.getCell(44).getCellStyle();
                                    CellStyle cellStyle45 = target.getCell(45).getCellStyle();
                                    CellStyle cellStyle46 = target.getCell(46).getCellStyle();
                                    CellStyle cellStyle47 = target.getCell(47).getCellStyle();
                                    CellStyle cellStyle48 = target.getCell(48).getCellStyle();
                                    CellStyle cellStyle49 = target.getCell(49).getCellStyle();
                                    CellStyle cellStyle50 = target.getCell(50).getCellStyle();
                                    CellStyle cellStyle51 = target.getCell(51).getCellStyle();
                                    CellStyle cellStyle52 = target.getCell(52).getCellStyle();
                                    CellStyle cellStyle53 = target.getCell(53).getCellStyle();
                                    CellStyle cellStyle54 = target.getCell(54).getCellStyle();
                                    CellStyle cellStyle55 = target.getCell(55).getCellStyle();
                                    CellStyle cellStyle56 = target.getCell(56).getCellStyle();
                                    CellStyle cellStyle57 = target.getCell(57).getCellStyle();
                                    CellStyle cellStyle58 = target.getCell(58).getCellStyle();
                                    CellStyle cellStyle59 = target.getCell(59).getCellStyle();
                                    CellStyle cellStyle60 = target.getCell(60).getCellStyle();
                                    CellStyle cellStyle61 = target.getCell(61).getCellStyle();
                                    CellStyle cellStyle62 = target.getCell(62).getCellStyle();
                                    CellStyle cellStyle63 = target.getCell(63).getCellStyle();
                                    CellStyle cellStyle64 = target.getCell(64).getCellStyle();
                                    CellStyle cellStyle65 = target.getCell(65).getCellStyle();
                                    CellStyle cellStyle66 = target.getCell(66).getCellStyle();
                                    CellStyle cellStyle67 = target.getCell(67).getCellStyle();
                                    CellStyle cellStyle68 = target.getCell(68).getCellStyle();
                                    CellStyle cellStyle69 = target.getCell(69).getCellStyle();
                                    CellStyle cellStyle70 = target.getCell(70).getCellStyle();
                                    CellStyle cellStyle71 = target.getCell(71).getCellStyle();
                                    CellStyle cellStyle72 = target.getCell(72).getCellStyle();
                                    CellStyle cellStyle73 = target.getCell(73).getCellStyle();
                                    CellStyle cellStyle74 = target.getCell(74).getCellStyle();
                                    CellStyle cellStyle75 = target.getCell(75).getCellStyle();
                                    CellStyle cellStyle76 = target.getCell(76).getCellStyle();
                                    CellStyle cellStyle77 = target.getCell(77).getCellStyle();
                                    CellStyle cellStyle78 = target.getCell(78).getCellStyle();
                                    CellStyle cellStyle79 = target.getCell(79).getCellStyle();
                                    CellStyle cellStyle80 = target.getCell(80).getCellStyle();
                                    CellStyle cellStyle81 = target.getCell(81).getCellStyle();
                                    CellStyle cellStyle82 = target.getCell(82).getCellStyle();
                                    CellStyle cellStyle83 = target.getCell(83).getCellStyle();
                                    CellStyle cellStyle84 = target.getCell(84).getCellStyle();
                                    CellStyle cellStyle85 = target.getCell(85).getCellStyle();
                                    CellStyle cellStyle86 = target.getCell(86).getCellStyle();
                                    CellStyle cellStyle87 = target.getCell(87).getCellStyle();
                                    CellStyle cellStyle88 = target.getCell(88).getCellStyle();
                                    CellStyle cellStyle89 = target.getCell(89).getCellStyle();
                                    CellStyle cellStyle90 = target.getCell(90).getCellStyle();
                                    CellStyle cellStyle91 = target.getCell(91).getCellStyle();
                                    CellStyle cellStyle92 = target.getCell(92).getCellStyle();
                                    CellStyle cellStyle93 = target.getCell(93).getCellStyle();
                                    CellStyle cellStyle94 = target.getCell(94).getCellStyle();
                                    CellStyle cellStyle95 = target.getCell(95).getCellStyle();
                                    CellStyle cellStyle96 = target.getCell(96).getCellStyle();
                                    CellStyle cellStyle97 = target.getCell(97).getCellStyle();
                                    CellStyle cellStyle98 = target.getCell(98).getCellStyle();
                                    CellStyle cellStyle99 = target.getCell(99).getCellStyle();
                                    CellStyle cellStyle100 = target.getCell(100).getCellStyle();
                                    CellStyle cellStyle101 = target.getCell(101).getCellStyle();
                                    CellStyle cellStyle102 = target.getCell(102).getCellStyle();
                                    CellStyle cellStyle103 = target.getCell(103).getCellStyle();
                                    CellStyle cellStyle104 = target.getCell(104).getCellStyle();
                                    CellStyle cellStyle105 = target.getCell(105).getCellStyle();
                                    CellStyle cellStyle106 = target.getCell(106).getCellStyle();
                                    CellStyle cellStyle107 = target.getCell(107).getCellStyle();
                                    CellStyle cellStyle108 = target.getCell(108).getCellStyle();
                                    cellType0.setCellStyle(cellStyle0);
                                    cellType1.setCellStyle(cellStyle1);
                                    cellType2.setCellStyle(cellStyle2);
                                    cellType3.setCellStyle(cellStyle3);
                                    cellType4.setCellStyle(cellStyle4);
                                    cellType5.setCellStyle(cellStyle5);
                                    cellType6.setCellStyle(cellStyle6);
                                    cellType7.setCellStyle(cellStyle7);
                                    cellType8.setCellStyle(cellStyle8);
                                    cellType9.setCellStyle(cellStyle9);
                                    cellType10.setCellStyle(cellStyle10);
                                    cellType11.setCellStyle(cellStyle11);
                                    cellType12.setCellStyle(cellStyle12);
                                    cellType13.setCellStyle(cellStyle13);
                                    cellType14.setCellStyle(cellStyle14);
                                    cellType15.setCellStyle(cellStyle15);
                                    cellType16.setCellStyle(cellStyle16);
                                    cellType17.setCellStyle(cellStyle17);
                                    cellType18.setCellStyle(cellStyle18);
                                    cellType19.setCellStyle(cellStyle19);
                                    cellType20.setCellStyle(cellStyle20);
                                    cellType21.setCellStyle(cellStyle21);
                                    cellType22.setCellStyle(cellStyle22);
                                    cellType23.setCellStyle(cellStyle23);
                                    cellType24.setCellStyle(cellStyle24);
                                    cellType25.setCellStyle(cellStyle25);
                                    cellType26.setCellStyle(cellStyle26);
                                    cellType27.setCellStyle(cellStyle27);
                                    cellType28.setCellStyle(cellStyle28);
                                    cellType29.setCellStyle(cellStyle29);
                                    cellType30.setCellStyle(cellStyle30);
                                    cellType31.setCellStyle(cellStyle31);
                                    cellType32.setCellStyle(cellStyle32);
                                    cellType33.setCellStyle(cellStyle33);
                                    cellType34.setCellStyle(cellStyle34);
                                    cellType35.setCellStyle(cellStyle35);
                                    cellType36.setCellStyle(cellStyle36);
                                    cellType37.setCellStyle(cellStyle37);
                                    cellType38.setCellStyle(cellStyle38);
                                    cellType39.setCellStyle(cellStyle39);
                                    cellType40.setCellStyle(cellStyle40);
                                    cellType41.setCellStyle(cellStyle41);
                                    cellType42.setCellStyle(cellStyle42);
                                    cellType43.setCellStyle(cellStyle43);
                                    cellType44.setCellStyle(cellStyle44);
                                    cellType45.setCellStyle(cellStyle45);
                                    cellType46.setCellStyle(cellStyle46);
                                    cellType47.setCellStyle(cellStyle47);
                                    cellType48.setCellStyle(cellStyle48);
                                    cellType49.setCellStyle(cellStyle49);
                                    cellType50.setCellStyle(cellStyle50);
                                    cellType51.setCellStyle(cellStyle51);
                                    cellType52.setCellStyle(cellStyle52);
                                    cellType53.setCellStyle(cellStyle53);
                                    cellType54.setCellStyle(cellStyle54);
                                    cellType55.setCellStyle(cellStyle55);
                                    cellType56.setCellStyle(cellStyle56);
                                    cellType57.setCellStyle(cellStyle57);
                                    cellType58.setCellStyle(cellStyle58);
                                    cellType59.setCellStyle(cellStyle59);
                                    cellType60.setCellStyle(cellStyle60);
                                    cellType61.setCellStyle(cellStyle61);
                                    cellType62.setCellStyle(cellStyle62);
                                    cellType63.setCellStyle(cellStyle63);
                                    cellType64.setCellStyle(cellStyle64);
                                    cellType65.setCellStyle(cellStyle65);
                                    cellType66.setCellStyle(cellStyle66);
                                    cellType67.setCellStyle(cellStyle67);
                                    cellType68.setCellStyle(cellStyle68);
                                    cellType69.setCellStyle(cellStyle69);
                                    cellType70.setCellStyle(cellStyle70);
                                    cellType71.setCellStyle(cellStyle71);
                                    cellType72.setCellStyle(cellStyle72);
                                    cellType73.setCellStyle(cellStyle73);
                                    cellType74.setCellStyle(cellStyle74);
                                    cellType75.setCellStyle(cellStyle75);
                                    cellType76.setCellStyle(cellStyle76);
                                    cellType77.setCellStyle(cellStyle77);
                                    cellType78.setCellStyle(cellStyle78);
                                    cellType79.setCellStyle(cellStyle79);
                                    cellType80.setCellStyle(cellStyle80);
                                    cellType81.setCellStyle(cellStyle81);
                                    cellType82.setCellStyle(cellStyle82);
                                    cellType83.setCellStyle(cellStyle83);
                                    cellType84.setCellStyle(cellStyle84);
                                    cellType85.setCellStyle(cellStyle85);
                                    cellType86.setCellStyle(cellStyle86);
                                    cellType87.setCellStyle(cellStyle87);
                                    cellType88.setCellStyle(cellStyle88);
                                    cellType89.setCellStyle(cellStyle89);
                                    cellType90.setCellStyle(cellStyle90);
                                    cellType91.setCellStyle(cellStyle91);
                                    cellType92.setCellStyle(cellStyle92);
                                    cellType93.setCellStyle(cellStyle93);
                                    cellType94.setCellStyle(cellStyle94);
                                    cellType95.setCellStyle(cellStyle95);
                                    cellType96.setCellStyle(cellStyle96);
                                    cellType97.setCellStyle(cellStyle97);
                                    cellType98.setCellStyle(cellStyle98);
                                    cellType99.setCellStyle(cellStyle99);
                                    cellType100.setCellStyle(cellStyle100);
                                    cellType101.setCellStyle(cellStyle101);
                                    cellType102.setCellStyle(cellStyle102);
                                    cellType103.setCellStyle(cellStyle103);
                                    cellType104.setCellStyle(cellStyle104);
                                    cellType105.setCellStyle(cellStyle105);
                                    cellType106.setCellStyle(cellStyle106);
                                    cellType107.setCellStyle(cellStyle107);
                                    cellType108.setCellStyle(cellStyle108);
                                }
                            }
                        }
                        long times = System.currentTimeMillis();
                        DCPluginProfile dcProfile = DCProfileManager.getDCProfile("com.awspaas.user.apps.processforsap", "mmData");
                        DCContext dcContext = new DCContext(uc, dcProfile, "com.awspaas.user.apps.processforsap", "mmData", times + "", "物料主数据【"+name+"】导出" + year + "." + month + EXTENSION_XLSX);
                        String path = dcContext.getPath();
                        File file1 = new File(path);
                        file1.mkdir();
                        excelFile = new FileOutputStream(dcContext.getFilePath());
                        wb.write(excelFile);
                        excelFile.flush();
                        String downloadURL = dcContext.getDownloadURL();
                        String replace = downloadURL.replace("sid=", "sid=" + sessionId + "");
                        responseObject.put("url", replace);
                    } else {
                        responseObject.err("模板生成失败！");
                    }
                }
            }
        } catch (
                Exception e) {
            e.printStackTrace();
            responseObject.err("打开失败");
        } finally {
            try {
                if (file != null) {
                    file.close();
                }
                if (excelFile != null) {
                    excelFile.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return responseObject.toString();
    }

    //
    @Mapping(value = "sap.downloadwltx")
    public static String upFilewltx(UserContext uc, String bindId) {
        ResponseObject responseObject = ResponseObject.newOkResponse("下载成功");
        String sessionId = uc.getSessionId();
        InputStream file = null;
        FileOutputStream excelFile = null;
        //日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
//        String[] fileNames = {"PROJECT_NAME", "PROJECT_NO", "PROJECT_DEPARTMENT", "XMJL", "SGJL", "FY_DATE", "FY_SCORE", "GQ_DATE", "GQ_SCORE", "TH_DATE", "TH_SCORE", "GS_DATE", "GS_SCORE", "IS_OK", "QUALITY_SCORE", "QUALITY_END", "SAFE_CHECK", "SAFE_SCORE", "SAFE_CHECK1", "SAFE_SCORE1", "SECURE_SCORE", "SCORE", "SECURE"};
//        String[] numFileNames = {"FY_SCORE", "GQ_SCORE", "TH_SCORE", "GS_SCORE", "QUALITY_SCORE", "QUALITY_END", "SAFE_SCORE", "SAFE_SCORE1", "SECURE_SCORE", "SCORE"};
        try {
            BO importModel = SDK.getBOAPI().query("BO_EU_MM_DCMB").addQuery("MODEL_ID = 'SAPFROWLTX'", null).detail();//导入模板表
            if (importModel != null) {

                String fileModel = importModel.getString("MODEL_FILE");
                if (fileModel != null && !"".equals(fileModel)) { //如果文件不为空
                    String name = "";
                    /** 获取对应附件 */
                    List<FormFile> file_model = SDK.getBOAPI().getFiles(importModel.getId(), "MODEL_FILE");
                    file = SDK.getBOAPI().getFile(file_model.get(0).getId());
                    /** 将对应附件解析 */
                    Workbook wb = null;
                    if (fileModel.endsWith(EXTENSION_XLS)) {
                        wb = new HSSFWorkbook(file);
                    } else if (fileModel.endsWith(EXTENSION_XLSX)) {
                        wb = new XSSFWorkbook(file);
                    }
                    int costIndex = 3;//项目费用清单行坐标
                    /** 找到对应行数据,并且将数据赋值进表格中 */
                    if (wb != null) {
                        Sheet sheet = wb.getSheetAt(0);
                        if (costIndex > 0) {
                            //获取基础视图
                            BO mainBo = SDK.getBOAPI().query("BO_EU_SAP_WLTX").bindId(bindId).detail();
                            List<BO> flList = SDK.getBOAPI().query("BO_EU_SAP_CPWLL").bindId(bindId).list();
                            List<BO> xsList = SDK.getBOAPI().query("BO_EU_SAP_ZCHJCH").bindId(bindId).list();
                            List<BO> cgList = SDK.getBOAPI().query("BO_EU_SAP_WAFER").bindId(bindId).list();
                            Row row = sheet.getRow(costIndex);//创建对应行数据
                            Cell cellType0 = row.getCell(0);
                            Cell cellType1 = row.getCell(1);
                            Cell cellType2 = row.getCell(2);
                            Cell cellType3 = row.getCell(3);
                            Cell cellType4 = row.getCell(4);
                            Cell cellType5 = row.getCell(5);
                            Cell cellType6 = row.getCell(6);
                            Cell cellType7 = row.getCell(7);
                            Cell cellType8 = row.getCell(8);
                            Cell cellType9 = row.getCell(9);
                            Cell cellType10 = row.getCell(10);
                            Cell cellType11 = row.getCell(11);
                            Cell cellType12 = row.getCell(12);
                            Cell cellType13 = row.getCell(13);
                            Cell cellType14 = row.getCell(14);
                            Cell cellType15 = row.getCell(15);
                            Cell cellType16 = row.getCell(16);
                            Cell cellType17 = row.getCell(17);
                            Cell cellType18 = row.getCell(18);
                            Cell cellType19 = row.getCell(19);
                            Cell cellType20 = row.getCell(20);
                            Cell cellType21 = row.getCell(21);
                            Cell cellType22 = row.getCell(22);
                            Cell cellType23 = row.getCell(23);
                            Cell cellType24 = row.getCell(24);
                            Cell cellType25 = row.getCell(25);
                            Cell cellType26 = row.getCell(26);
                            Cell cellType27 = row.getCell(27);
                            Cell cellType28 = row.getCell(28);
                            Cell cellType29 = row.getCell(29);
                            Cell cellType30 = row.getCell(30);
                            Cell cellType31 = row.getCell(31);
                            Cell cellType32 = row.getCell(32);
                            Cell cellType33 = row.getCell(33);
                            Cell cellType34 = row.getCell(34);
                            Cell cellType35 = row.getCell(35);
                            Cell cellType36 = row.getCell(36);
                            Cell cellType37 = row.getCell(37);
                            Cell cellType38 = row.getCell(38);
                            Cell cellType39 = row.getCell(39);
                            Cell cellType40 = row.getCell(40);
                            Cell cellType41 = row.getCell(41);
                            Cell cellType42 = row.getCell(42);
                            Cell cellType43 = row.getCell(43);
                            Cell cellType44 = row.getCell(44);
                            Cell cellType45 = row.getCell(45);
                            Cell cellType46 = row.getCell(46);
                            Cell cellType47 = row.getCell(47);
                            Cell cellType48 = row.getCell(48);
                            Cell cellType49 = row.getCell(49);
                            Cell cellType50 = row.getCell(50);
                            Cell cellType51 = row.getCell(51);
                            Cell cellType52 = row.getCell(52);
                            Cell cellType53 = row.getCell(53);
                            Cell cellType54 = row.getCell(54);
                            Cell cellType55 = row.getCell(55);
                            Cell cellType56 = row.getCell(56);
                            Cell cellType57 = row.getCell(57);
                            Cell cellType58 = row.getCell(58);
                            Cell cellType59 = row.getCell(59);
                            Cell cellType60 = row.getCell(60);
                            Cell cellType61 = row.getCell(61);
                            Cell cellType62 = row.getCell(62);
                            Cell cellType63 = row.getCell(63);
                            Cell cellType64 = row.getCell(64);
                            Cell cellType65 = row.getCell(65);
                            Cell cellType66 = row.getCell(66);
                            Cell cellType67 = row.getCell(67);
                            Cell cellType68 = row.getCell(68);
                            Cell cellType69 = row.getCell(69);
                            Cell cellType70 = row.getCell(70);
                            Cell cellType71 = row.getCell(71);
                            Cell cellType72 = row.getCell(72);
                            Cell cellType73 = row.getCell(73);
                            BO bo = new BO();
                            String name1 = mainBo.getString("MATNR");
                            name = name1;
                            cellType0.setCellValue(name1);
                            if (flList != null && flList.size() > 0) {
                                //获取行数据
                                bo = flList.get(0);
                                //赋值

                                //产成品
                                cellType1.setCellValue(bo.getString("Z_PROD_MAT"));
                                cellType2.setCellValue(bo.getString("ZCUSTOMCODE"));
                                cellType3.setCellValue(bo.getString("ZMFG"));
                                cellType4.setCellValue(bo.getString("ZMODEL"));
                                cellType5.setCellValue(bo.getString("ZWAFERTYPE"));
                                cellType6.setCellValue(bo.getString("ZASSEMTYPE"));
                                cellType7.setCellValue(bo.getString("ZAPPLIEDTERMINAL"));
                                cellType8.setCellValue(bo.getString("ZCATEGORY"));
                                cellType9.setCellValue(bo.getString("DEVICE"));
                                cellType10.setCellValue(bo.getString("ZBALLCOUNT"));
                                cellType11.setCellValue(bo.getString("ZENDUSER"));
                                cellType12.setCellValue(bo.getString("ZFIFO"));
                                cellType13.setCellValue(bo.getString("ZSPEC"));
                                cellType14.setCellValue(bo.getString("ZGYUNIT"));
                                cellType15.setCellValue(bo.getString("ZMATNAME"));
                                cellType16.setCellValue(bo.getString("ZTYPE"));
                            }
                            //分类视图
                            if (xsList != null && xsList.size() > 0) {
                                bo = xsList.get(0);
                                cellType17.setCellValue(bo.getString("Z_ROH_MAT"));
                                cellType18.setCellValue(bo.getString("ZHSCODE"));
                                cellType19.setCellValue(bo.getString("ZCOUSTOMCONTROL"));
                                cellType20.setCellValue(bo.getString("ZMATSTATUS"));
                                cellType21.setCellValue(bo.getString("ZMODEL"));
                                cellType22.setCellValue(bo.getString("ZMATTYPE"));
                                cellType23.setCellValue(bo.getString("ZTEXTURE"));
                                cellType24.setCellValue(bo.getString("ZDLT"));
                                cellType25.setCellValue(bo.getString("ZCMATNRDESC"));
                                cellType26.setCellValue(bo.getString("ZSIZE"));
                                cellType27.setCellValue(bo.getString("ZKEY"));
                                cellType28.setCellValue(bo.getString("ZCUSTOMER"));
                                cellType29.setCellValue(bo.getString("ZCMATNR"));
                                cellType30.setCellValue(bo.getString("ZBODYSIZE"));
                                cellType31.setCellValue(bo.getString("ZPADSIZE"));
                                cellType32.setCellValue(bo.getString("ZLEADCOUNT"));
                                cellType33.setCellValue(bo.getString("ZMATRIX"));
                                cellType34.setCellValue(bo.getString("ZCOMPTYPE"));
                                cellType35.setCellValue(bo.getString("ZGS"));
                                cellType36.setCellValue(bo.getString("ZANTISTATIC"));
                                cellType37.setCellValue(bo.getString("ZCALIBRATE"));
                                cellType38.setCellValue(bo.getString("ZCAL"));
                                cellType39.setCellValue(bo.getString("ZSUBTYPE"));
                                cellType40.setCellValue(bo.getString("ZCORE"));
                                cellType41.setCellValue(bo.getString("ZCARMATER"));
                                cellType42.setCellValue(bo.getString("ZHIGHTHERMAL"));
                                cellType43.setCellValue(bo.getString("ZNONINSP"));
                                cellType44.setCellValue(bo.getString("ZFIFO"));
                                cellType45.setCellValue(bo.getString("ZMESMATNR"));
                                cellType46.setCellValue(bo.getString("ZSPEC"));
                                cellType47.setCellValue(bo.getString("ZGYUNIT"));
                                cellType48.setCellValue(bo.getString("ZMATNAME"));
                                cellType49.setCellValue(bo.getString("ZTEST_F"));
                                cellType50.setCellValue(bo.getString("ZTEST_V"));
                                cellType51.setCellValue(bo.getString("ZTYPE"));
                                cellType52.setCellValue(bo.getString("ZHAVECU"));
                                cellType53.setCellValue(bo.getString("ZLAYER"));
                            }

                            //会计视图
                            if (cgList != null && cgList.size() > 0) {
                                bo = cgList.get(0);
                                cellType54.setCellValue(bo.getString("Z_WAFER_MAT"));
                                cellType55.setCellValue(bo.getString("ZCUSTOMCODE"));
                                cellType56.setCellValue(bo.getString("ZMFG"));
                                cellType57.setCellValue(bo.getString("ZMODEL"));
                                cellType58.setCellValue(bo.getString("ZWAFERTYPE"));
                                cellType59.setCellValue(bo.getString("ZASSEMTYPE"));
                                cellType60.setCellValue(bo.getString("ZAPPLIEDTERMINAL"));
                                cellType61.setCellValue(bo.getString("ZCATEGORY"));
                                cellType62.setCellValue(bo.getString("ZWAFERSIZE"));
                                cellType63.setCellValue(bo.getString("ZCMATNR"));
                                cellType64.setCellValue(bo.getString("ZMEMS"));
                                cellType65.setCellValue(bo.getString("ZGAAS"));
                                cellType66.setCellValue(bo.getString("ZFIFO"));
                                cellType67.setCellValue(bo.getString("ZNONINSP"));
                                cellType68.setCellValue(bo.getString("ZNOTCH"));
                                cellType69.setCellValue(bo.getString("ZSPEC"));
                                cellType70.setCellValue(bo.getString("ZGYUNIT"));
                                cellType71.setCellValue(bo.getString("ZMATNAME"));
                                cellType72.setCellValue(bo.getString("ZIMPTYPE"));
                                cellType73.setCellValue(bo.getString("ZTYPE"));

                            }
                        }
                        long times = System.currentTimeMillis();
                        DCPluginProfile dcProfile = DCProfileManager.getDCProfile("com.awspaas.user.apps.processforsap", "mmData");
                        DCContext dcContext = new DCContext(uc, dcProfile, "com.awspaas.user.apps.processforsap", "mmData", times + "", "物料特性数据导出【"+name+"】" + year + "." + month + EXTENSION_XLSX);
                        String path = dcContext.getPath();
                        File file1 = new File(path);
                        file1.mkdir();
                        excelFile = new FileOutputStream(dcContext.getFilePath());
                        wb.write(excelFile);
                        excelFile.flush();
                        String downloadURL = dcContext.getDownloadURL();
                        String replace = downloadURL.replace("sid=", "sid=" + sessionId + "");
                        responseObject.put("url", replace);
                    } else {
                        responseObject.err("模板生成失败！");
                    }
                }
            }
        } catch (
                Exception e) {
            e.printStackTrace();
            responseObject.err("打开失败");
        } finally {
            try {
                if (file != null) {
                    file.close();
                }
                if (excelFile != null) {
                    excelFile.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return responseObject.toString();
    }
}
